package com.bstek.demo.urule.cluster.mq.redis.service;

import com.bstek.demo.urule.cluster.mq.CustomCacheService;
import com.bstek.demo.urule.cluster.mq.MQConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service(CustomCacheService.BEAN_ID)
public class RedisCacheServiceImpl implements CustomCacheService {

    Logger log= LoggerFactory.getLogger(RedisCacheServiceImpl.class);

    @Value("${urule.knowledgePackageFileStorePath}")
    String knowledgePackageFileStorePath;

    @Resource(name = "redisTemplate2")
    RedisTemplate<String, byte[]> redisTemplate2;

    @Override
    public byte[] getCache(long id) {
        String key= MQConstant.CACHE_PREFIX + id;
        log.info("redis-key={}",key);
        return redisTemplate2.opsForValue().get(key);
    }

    @Override
    public boolean existCache(long id) {
        String key= MQConstant.CACHE_PREFIX + id;
        return redisTemplate2.hasKey(key);
    }

    @Override
    public String getKnowledgePackageFileStorePath() {
        return knowledgePackageFileStorePath;
    }

}
